<template>
  <van-icon
    :color="likeCount ? 'yellow' : '#777'"
    :name="likeCount ? 'thumb-circle' : 'thumb-circle-o'"
    @click="onLink"
  />
</template>

<script>
import { deleteLink, addLink } from "@/api/article";
export default {
  name: "Link",
  props: {
    id: {
      typeof: [String, Number],
      required: true,
    },
    likeCount: {
      typeof: Number,
      require: true,
    },
  },
  methods: {
    async onLink() {
    try {
          this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
      });
      if (this.likeCount) {
        await deleteLink(this.id);
      } else {
        await addLink(this.id);
      }
      this.$emit("update:likeCount", this.likeCount ? 0 : 1);
    } finally{
        this.$toast.clear
    }
    },
  },
};
</script>

<style>
</style>